package ntest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import com.example.hello_world.R;

public class task2_1 extends AppCompatActivity {

    private TextView tv;
    private Spinner spinner;
    private ArrayAdapter<String> adapter;
    private String[] strings;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task2_1);
        tv=findViewById(R.id.task2_1_text);
        spinner=findViewById(R.id.task2_1_spinner);
        strings=getResources().getStringArray(R.array.spinner);
        adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,strings);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                tv.setText(adapter.getItem(position));
                //tv.getText();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }
}